package tmt.usercenter.web.controller.admin;


import com.tmt.datatable.TableRequest;
import com.tmt.datatable.TableResponse;
import com.tmt.datatable.editor.EditorModel;
import com.tmt.datatable.editor.EditorValid;
import com.tmt.datatable.ext.controller.DataTableController;
import com.tmt.datatable.ext.controller.TablePage;
import lombok.Getter;
import lombok.Setter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import tmt.usercenter.web.common.Const;
import tmt.usercenter.web.domain.TmtAuthority;
import tmt.usercenter.web.service.TmtAuthorityService;

import javax.validation.Valid;
import java.util.HashMap;
import java.util.concurrent.ExecutionException;

@Getter
@Setter
@RequestMapping(Const.ADMIN_PATH + "/authority")
@TablePage(Const.ADMIN_PATH + "/authority/authority-index")
@Controller("admin-authority-controller")
public class AuthorityController extends DataTableController<TmtAuthority, Long> {

    @Autowired
    private TmtAuthorityService tmtAuthorityService;

    @Override
    public TableResponse getTableData(TableRequest tRequest, Model model) throws ExecutionException, InterruptedException {
        TableResponse response = getTableResponse(tRequest, model,  new String[]{"creator"}, new HashMap<>(), new HashMap<>(), new HashMap<>()).get();
        return response;
    }

    @Override
    public EditorModel<TmtAuthority> doTableAction(@Valid @EditorValid EditorModel<TmtAuthority> editor) throws ExecutionException, InterruptedException {
        EditorModel<TmtAuthority> model = executeTableAction(editor, new String[]{"creator"}).get();
        return model;
    }
}
